import Components from "@/components";
import { ElMessage, ElLoading, ElMessageBox } from "element-plus";

class Plugin {
    static _instance = null;
    static renderInstance() {
        if (!Plugin._instance) Plugin._instance = new Plugin();
        return Plugin._instance;
    }

    install(app, _) {
        Components.globalRegister(app);
        this.useGlobalInstance(app);
    }

    useGlobalInstance(app) {
        app.config.globalProperties.$message = ElMessage;
        app.config.globalProperties.$loading = ElLoading;
        app.config.globalProperties.$messageBox = ElMessageBox;
    }

    piniaPlugin({ store }) {
        store.validtorImageType = function (type) {
            const typeList = this.imageType;
            if (!typeList.includes(type))
                throw new Error(
                    "上传文件不合法, 支持的文件为:" + typeList.join("、")
                );
        };
    }
}
export default Plugin.renderInstance();
